#!/bin/bash
#

function check_redis() {
    PORT="6379"

    netstat -tunlp | grep "redis" &> /dev/null
    REVTAL=$?
    
    if [ $REVTAL -eq 0 ]; then 
        redis_pid=`netstat -tunlp | grep redis | grep -v "::1" | grep ${PORT} | awk '{print $7}' | awk -F '/' '{print $1}'`
        echo "$(date +%Y-%m-%d" "%H:%M:%S) - - redis service is running: ${redis_pid}."
    else
        /usr/local/redis/bin/redis-server -c /usr/local/redis/redis.conf 
        echo "redis service start."
    fi
}


while true; do
    check_redis
    sleep 60s
done